From c1124c599381cbd33eb305a4240387048effbeea Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Fri, 5 May 2006 18:36:12 +0100 Subject: [PATCH] Use the auxbin module to find the appropriate install directory for our Python scripts. This fixes a bug with xm-test not working on 64-bit systems. Signed-off-by: Ewan Mellor --- tools/misc/xend | 24 ++++++++++++++++++++---- tools/python/xen/util/auxbin.py | 19 ++++++++++++------- tools/xm-test/configure.ac | 2 +- tools/xm-test/lib/XmTestLib/__init__.py | 20 +++++++++++++++++--- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/tools/misc/xend b/tools/misc/xend index f2db3c100b..cd35438090 100644 --- a/tools/misc/xend +++ b/tools/misc/xend @@ -2,7 +2,7 @@ # -*- mode: python; -*- #============================================================================ # Copyright (C) 2004 Mike Wray -# Copyright (C) 2005 XenSource Ltd +# Copyright (C) 2005-2006 XenSource Inc #============================================================================ """Xen management daemon. @@ -21,15 +21,31 @@ and recover its state when restarted. """ import os +import os.path import sys import socket import signal import time import commands -# add fallback path for non-native python path installs if needed -sys.path.append('/usr/lib/python') -sys.path.append('/usr/lib64/python') + +# Use the auxbin module in Xend to determine the correct Python path. We +# take the first installed instance of auxbin that we find, and then run it +# to determine the correct path, appending that to sys.path. + +AUXBIN = 'xen/util/auxbin.py' + +for p in ['python%s' % sys.version[:3], 'python']: + for l in ['/usr/lib64', '/usr/lib']: + d = os.path.join(l, p) + if os.path.exists(os.path.join(d, AUXBIN)): + sys.path.append(d) + import xen.util.auxbin + libpath = xen.util.auxbin.libpath() + sys.path = sys.path[:-1] + sys.path.append(libpath) + break + from xen.xend.server import SrvDaemon class CheckError(ValueError): diff --git a/tools/python/xen/util/auxbin.py b/tools/python/xen/util/auxbin.py index 06cd500b4b..ba8aba182a 100644 --- a/tools/python/xen/util/auxbin.py +++ b/tools/python/xen/util/auxbin.py @@ -12,14 +12,15 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #============================================================================ -# Copyright (C) 2005 XenSource Ltd +# Copyright (C) 2005-2006 XenSource Inc. #============================================================================ -LIB_BIN_32 = "/usr/lib/xen/bin" -LIB_BIN_64 = "/usr/lib64/xen/bin" +LIB_32 = "/usr/lib" +LIB_64 = "/usr/lib64" +LIB_BIN_SUFFIX = "xen/bin" -## The architectures on which the LIB_BIN_64 directory is used. This +## The architectures on which the LIB_64 directory is used. This # deliberately excludes ia64. LIB_64_ARCHS = [ 'x86_64', 'ppc64', 's390x', 'sparc64'] @@ -41,8 +42,12 @@ def pathTo(exe): def path(): + return os.path.join(libpath(), LIB_BIN_SUFFIX) + + +def libpath(): machine = os.uname()[4] - if machine in LIB_64_ARCHS and os.path.exists(LIB_BIN_64): - return LIB_BIN_64 + if machine in LIB_64_ARCHS and os.path.exists(LIB_64): + return LIB_64 else: - return LIB_BIN_32 + return LIB_32 diff --git a/tools/xm-test/configure.ac b/tools/xm-test/configure.ac index 44d81b224e..eecbf7863a 100644 --- a/tools/xm-test/configure.ac +++ b/tools/xm-test/configure.ac @@ -13,7 +13,7 @@ AC_CHECK_PROG([LILO], lilo, lilo, "no", [$PATH]) # are two levels above the tests TESTLIB=../../lib RD_PATH=../../ramdisk -TENV="PYTHONPATH=$PYTHONPATH:$TESTLIB:/usr/lib/python RD_PATH=$RD_PATH" +TENV="PYTHONPATH=$PYTHONPATH:$TESTLIB RD_PATH=$RD_PATH" AC_ARG_ENABLE(hvm-support, [[ --enable-hvm-support enable hardware virtual machine assist]], diff --git a/tools/xm-test/lib/XmTestLib/__init__.py b/tools/xm-test/lib/XmTestLib/__init__.py index af58a5ef97..7127383067 100644 --- a/tools/xm-test/lib/XmTestLib/__init__.py +++ b/tools/xm-test/lib/XmTestLib/__init__.py @@ -11,11 +11,25 @@ from config import * from XenDevice import * from NetConfig import * -# Make sure xen modules are in path -sys.path.append('/usr/lib/python') +# Use the auxbin module in Xend to determine the correct Python path. We +# take the first installed instance of auxbin that we find, and then run it +# to determine the correct path, appending that to sys.path. + +AUXBIN = 'xen/util/auxbin.py' + +for p in ['python%s' % sys.version[:3], 'python']: + for l in ['/usr/lib64', '/usr/lib']: + d = os.path.join(l, p) + if os.path.exists(os.path.join(d, AUXBIN)): + sys.path.append(d) + import xen.util.auxbin + libpath = xen.util.auxbin.libpath() + sys.path = sys.path[:-1] + sys.path.append(libpath) + break # Give this test a clean slate -destroyAllDomUs(); +destroyAllDomUs() if os.environ.get("TEST_VERBOSE"): verbose = True -- 2.30.2